﻿#ifndef UI_HOME_H
#define UI_HOME_H

#include <QMainWindow>
#include <QTcpSocket>
#include <QThread>
#include <QLabel>
#include "work_tcp.h"
#include "ui_seach.h"
#include "cluster.h"

namespace Ui {
class uiHome;
}

class uiHome : public QMainWindow
{
    Q_OBJECT

public:
    explicit uiHome(QWidget *parent = 0);
    ~uiHome();

    void retError(int ret);

//protected:
//    void closeEvent(QCloseEvent *event) override;

signals:
    void tcpConnect(void);
    void searchLocalDev(int);
    void setMotor(QString);
    void clusterReboot(QString, int, QString, int);
    void setLocal(QString);
    void setCluster(QString);
    void setCmd(QString);
    void setDna(QString);
    void getCmd(QString);
    void getDna(QString);
    void refrCmd(LocalDev *);
    void refrDna(LocalDev *);

private slots:
    void on_seachCluster_clicked();

    void tcpConnectCluster(udpDeviceInfo_t dev);

    void on_clusterInfo_clicked();

    void on_dropBus_currentIndexChanged(int index);

    void on_pushButton_3_clicked();

    void on_pushButton_4_clicked();

    void on_pushButton_5_clicked();

    void on_stop_clicked();

    void on_stop_2_clicked();

private:
    void homeInit(void);
    void ShowHMI(void);
    void refrMotor(LocalDev * ld);

    Ui::uiHome      *ui;

    uiSeach         * ui_search     = nullptr;
    QThread         * m_t           = nullptr;
    WorkTcp         * m_work        = nullptr;
    udpDeviceInfo_t * m_cluster     = nullptr;
    LocalDev        * m_curLocalDev = nullptr;
    Cluster         * m_clus        = nullptr;

    QLabel          * m_statusText;
    QLabel          * m_motorRefrTime;
    bool            m_isConnect     = false;
};

#endif // UI_HOME_H
